// Cards
jQuery.fn.cards = function () {
	jQuery(this).find("td").click(function () {
		var td = jQuery(this), cardWidth = (td.hasClass("card-type-life") ? 45 : 150),
		btnClose = jQuery(td).parentsUntil(".dialog").find("input[type='reset']");
		// Assign un/selected classes to this and it's siblings (the other cells), and remove click event
		td.addClass("selected").siblings().addClass("unselected").add(td).unbind("click");
		// Animate card back
		td.find(".card-back").animate({width: 0, marginLeft:cardWidth/2}, function () {
			// When card-back finishes animating, animate card front
			td.find(".card-front").css({width:0, marginLeft:cardWidth/2, display:"inline"}).animate({width:cardWidth, marginLeft:0});
		});
		
		// Talk to server indicating the card which was selected
		// Show loading status in button
		btnClose.attr("disabled", "disabled").val("Loading...");
		// Do post
		jQuery.post("play-actions.php", {
			"cardSubmit": true, 
			"type": td.parentsUntil("table.cards").parent().attr("type"),
			"id" :td.attr("cardId"),
			"stealFrom": td.attr("stealFrom")
		}, function () {
			// Once loaded, have button cause page reload
			btnClose.removeAttr("disabled").val("Close").unbind("click").click(function () {
				window.location = "play.php";
			});
		});
	});
}
